#mapping-script
# -*- coding: ms949 -*-
import bots.transform as transform
import bots.usersys.mappings.utils as utils

def main(inn,out):
    #XML
    rootelement = '{urn:kr:gov:kcs:data:standard:KCS_CarryInReportSchemaModule:1:0:0}CarryInReport'
    ns1 = '{urn:kr:gov:kcs:data:standard:KCS_CarryInReportSchemaModule:1:0:0}'
    ns2 = '{urn:kr:gov:kcs:common:standard:KCS_ReusableAggregateBusinessInformationEntitySchemaModule:1:0:0}'
    
    #Read from inn by EDIFACT order
    DocumentTypeCode = inn.get({'BOTSID':'UNH'},{'BOTSID':'BGM','C002.1001':None})
    DocumentReferenceID = inn.get({'BOTSID':'UNH'},{'BOTSID':'BGM','1004':None})
    DocumentFunctionTypeCode = inn.get({'BOTSID':'UNH'},{'BOTSID':'BGM','1225':None})
    
    CarryInDateTime = inn.get({'BOTSID':'UNH'},{'BOTSID':'DTM','C507.2005':'50','C507.2380':None})
    
    WarehouseCodeID = inn.get({'BOTSID':'UNH'},{'BOTSID':'LOC','3227':'18','C517.3225':None})
    
    CargoCarryInTypeCode = inn.get({'BOTSID':'UNH'},{'BOTSID':'GIS','C529.1131':'109','C529.7365':None})        #Common Code Conversion required
    PartitionCarryInTypeCode = inn.get({'BOTSID':'UNH'},{'BOTSID':'GIS','C529.1131':'121','C529.7365':None})    #Common Code Conversion required
    UseTypeCode = inn.get({'BOTSID':'UNH'},{'BOTSID':'GIS','C529.1131':'119','C529.7365':None})                 #Common Code Conversion required
    
    UCRIdentificationID = inn.get({'BOTSID':'UNH'},{'BOTSID':'RFF','C506.1153':'XC','C506.1154':None})
    UCRMasterBLSequenceID = inn.get({'BOTSID':'UNH'},{'BOTSID':'RFF','C506.1153':'XC','C506.1156':None})
    UCRHouseBLSequenceID = inn.get({'BOTSID':'UNH'},{'BOTSID':'RFF','C506.1153':'XC','C506.4000':None})
    PreviousCustomsDocumentReferenceID = inn.get({'BOTSID':'UNH'},{'BOTSID':'RFF','C506.1153':'ABP','C506.1154':None})
    
    CarryInGoodsPackagingQuantity = inn.get({'BOTSID':'UNH'},{'BOTSID':'GID','C213#1.7224':None})
    CarryInGoodsPackagingTypeCode = inn.get({'BOTSID':'UNH'},{'BOTSID':'GID','C213#1.7065':None})
    
    AbnormalityTypeCode = inn.get({'BOTSID':'UNH'},{'BOTSID':'GID'},{'BOTSID':'FTX','4451':'ACD','C108.4440#1':None})
    
    CarryInMeasureUnitCode = inn.get({'BOTSID':'UNH'},{'BOTSID':'GID'},{'BOTSID':'MEA','6311':'WT','C174.6411':'KG','C174.6411':None})
    CarryInMeasure = inn.get({'BOTSID':'UNH'},{'BOTSID':'GID'},{'BOTSID':'MEA','6311':'WT','C174.6411':'KG','C174.6314':None})
    
    AbnormalityMeasureUnitCode = inn.get({'BOTSID':'UNH'},{'BOTSID':'GID'},{'BOTSID':'MEA','6311':'WT','C502.6155':'14','C174.6411':'KG','C174.6411':None})
    AbnormalityMeasure = inn.get({'BOTSID':'UNH'},{'BOTSID':'GID'},{'BOTSID':'MEA','6311':'WT','C502.6155':'14','C174.6411':'KG','C174.6314':None})
    
    AbnormalityGoodsPackagingTypeCode = inn.get({'BOTSID':'UNH'},{'BOTSID':'GID'},{'BOTSID':'MEA','6311':'CT','C502.6155':'14','C174.6411':'CT','C174.6411':None})
    AbnormalityGoodsPackagingQuantity = inn.get({'BOTSID':'UNH'},{'BOTSID':'GID'},{'BOTSID':'MEA','6311':'CT','C502.6155':'14','C174.6411':'CT','C174.6314':None})
    
    PartitionCarriedInGradeNumeric = inn.get({'BOTSID':'UNH'},{'BOTSID':'CNT','C270.6069':'6','C270.6066':None})
    
    
    out.ta_info['botskey'] = 'CUSCAR-632-' + DocumentReferenceID.strip()
    
    #Write to out by XML order
    out.put({'BOTSID':rootelement,ns1+'CarryInReport__{http://www.w3.org/2001/XMLSchema-instance}schemaLocation':'urn:kr:gov:kcs:data:standard:KCS_CarryInReportSchemaModule:1:0:0 ./schema/uncefact/data/KCS_CarryInReportSchemaModule_1.0.0_standard.xsd'})
    
    out.put({'BOTSID':rootelement,ns1+'CarryInDateTime':utils.isoDateTimeFormat(CarryInDateTime)})
    out.put({'BOTSID':rootelement,ns1+'CargoCarryInTypeCode':CargoCarryInTypeCode})
    out.put({'BOTSID':rootelement,ns1+'PartitionCarryInTypeCode':PartitionCarryInTypeCode})
    out.put({'BOTSID':rootelement,ns1+'UseTypeCode':UseTypeCode})
    out.put({'BOTSID':rootelement,ns1+'AbnormalityTypeCode':AbnormalityTypeCode})
    out.put({'BOTSID':rootelement,ns1+'CarryInMeasure':CarryInMeasure})
    out.put({'BOTSID':rootelement,ns1+'CarryInMeasure__measureUnitCode':CarryInMeasureUnitCode})
    out.put({'BOTSID':rootelement,ns1+'AbnormalityMeasure':AbnormalityMeasure})
    out.put({'BOTSID':rootelement,ns1+'AbnormalityMeasure__measureUnitCode':AbnormalityMeasureUnitCode})
    out.put({'BOTSID':rootelement,ns1+'PartitionCarriedInGradeNumeric':PartitionCarriedInGradeNumeric})
    
    
    out.put({'BOTSID':rootelement},{'BOTSID':ns1+'Document',ns2+'TypeCode':DocumentTypeCode})
    out.put({'BOTSID':rootelement},{'BOTSID':ns1+'Document',ns2+'referenceID':DocumentReferenceID})
    out.put({'BOTSID':rootelement},{'BOTSID':ns1+'Document',ns2+'FunctionTypeCode':DocumentFunctionTypeCode})
    
    out.put({'BOTSID':rootelement},{'BOTSID':ns1+'Warehouse',ns2+'CodeID':WarehouseCodeID})
    
    out.put({'BOTSID':rootelement},{'BOTSID':ns1+'UCR',ns2+'IdentificationID':UCRIdentificationID})
    out.put({'BOTSID':rootelement},{'BOTSID':ns1+'UCR',ns2+'MasterBLSequenceID':UCRMasterBLSequenceID})
    out.put({'BOTSID':rootelement},{'BOTSID':ns1+'UCR',ns2+'HouseBLSequenceID':UCRHouseBLSequenceID})
    
    out.put({'BOTSID':rootelement},{'BOTSID':ns1+'PreviousCustomsDocument',ns2+'referenceID':PreviousCustomsDocumentReferenceID})
    
    out.put({'BOTSID':rootelement},{'BOTSID':ns1+'CarryInGoodsPackaging',ns2+'Quantity':CarryInGoodsPackagingQuantity})
    out.put({'BOTSID':rootelement},{'BOTSID':ns1+'CarryInGoodsPackaging',ns2+'TypeCode':CarryInGoodsPackagingTypeCode})
    
    out.put({'BOTSID':rootelement},{'BOTSID':ns1+'AbnormalityGoodsPackaging',ns2+'Quantity':AbnormalityGoodsPackagingQuantity})
    out.put({'BOTSID':rootelement},{'BOTSID':ns1+'AbnormalityGoodsPackaging',ns2+'TypeCode':AbnormalityGoodsPackagingTypeCode})
